﻿<UserControl x:Class="TerribleFate.CountdownControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:p="clr-namespace:TerribleFate.Properties"
             xmlns:local="clr-namespace:TerribleFate"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d"  x:Name="window" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled"
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <ResourceDictionary>
            <local:ColorToSolidColorBrushValueConverter x:Key="c2b" />
            <LinearGradientBrush x:Key="DefaultButtonGradient" StartPoint="0,0"  EndPoint="1,1">
                <GradientStop Color="{Binding Config.ButtonColor1}" Offset="0" />
                <GradientStop Color="{Binding Config.ButtonColor2}" Offset="1" />
            </LinearGradientBrush>
            <LinearGradientBrush x:Key="RedButtonGradient">
                <GradientStop Color="{Binding Config.TrashButtonColor1}" Offset="0" />
                <GradientStop Color="{Binding Config.TrashButtonColor2}" Offset="1" />
            </LinearGradientBrush>
            <LinearGradientBrush x:Key="ActivatedButtonGradient">
                <GradientStop Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}, AncestorLevel=1}, Path=DataContext.Config.ToggleButtonColor1}" Offset="0" />
                <GradientStop Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}, AncestorLevel=1}, Path=DataContext.Config.ToggleButtonColor2}" Offset="1" />
            </LinearGradientBrush>
            <DropShadowEffect x:Key="HoverShadowEffect" Color="{x:Static SystemColors.ActiveCaptionColor}" BlurRadius="10" ShadowDepth="0" />
            <SolidColorBrush Color="{Binding Config.TextBorderColor}" x:Key="TextBorderBrush" />
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid Background="#01000000" MouseEnter="Grid_MouseEnter" MouseLeave="Grid_MouseLeave">
        <Grid.ContextMenu>
            <ContextMenu>
                <MenuItem Header="{x:Static p:Resources.Info}" Command="{Binding InfoCommand}" />
                <MenuItem Header="{x:Static p:Resources.Lock}" IsCheckable="True" IsChecked="{Binding Locked}" />
                <Separator />
                <MenuItem Header="{x:Static p:Resources.Exit}" Command="{Binding CloseCommand}" CommandParameter="{Binding ElementName=window}" >
                 
                </MenuItem>
            </ContextMenu>
        </Grid.ContextMenu>
        <Grid.Resources>
            <BooleanToVisibilityConverter x:Key="b2v" />
            <local:ParametrizedBooleanToVisibilityConverter x:Key="pb2v" />
            <local:TimeSpanToStringConverter x:Key="tsts" />
           

            <Style x:Key="LockStyle" TargetType="ToggleButton">
                <Setter Property="Width" Value="18" />
                <Setter Property="Height" Value="18" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Grid>
                                <Rectangle Name="img" Fill="{StaticResource DefaultButtonGradient}">
                                    <Rectangle.OpacityMask>
                                        <ImageBrush ImageSource="Icons/appbar.lock.png"/>
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="ToggleButton.IsChecked" Value="True">
                                    <Setter TargetName="img" Property="OpacityMask">
                                        <Setter.Value>
                                            <ImageBrush ImageSource="Icons/appbar.unlock.keyhole.png"/>
                                        </Setter.Value>
                                    </Setter>
                                </Trigger>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Effect" TargetName="img" Value="{StaticResource HoverShadowEffect}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <Style x:Key="InactiveStyle" TargetType="ToggleButton">
                <Setter Property="Width" Value="20" />
                <Setter Property="Height" Value="20" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Grid>
                                <Rectangle Name="img" Fill="{StaticResource DefaultButtonGradient}">
                                    <Rectangle.OpacityMask>
                                        <ImageBrush ImageSource="Icons/appbar.magnify.add.png"/>
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="ToggleButton.IsChecked" Value="True">
                                    <Setter TargetName="img" Property="OpacityMask">
                                        <Setter.Value>
                                            <ImageBrush ImageSource="Icons/appbar.magnify.minus.png"/>
                                        </Setter.Value>
                                    </Setter>
                                </Trigger>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Effect" TargetName="img" Value="{StaticResource HoverShadowEffect}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <Style x:Key="NewStyle" TargetType="Button">
                <Setter Property="Width" Value="18" />
                <Setter Property="Height" Value="18" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Grid>
                                <Rectangle Name="img" Fill="{StaticResource DefaultButtonGradient}">
                                    <Rectangle.OpacityMask>
                                        <ImageBrush ImageSource="Icons/appbar.add.png"/>
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Effect" TargetName="img" Value="{StaticResource HoverShadowEffect}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <Style x:Key="MuteStyle" TargetType="Button">
                <Setter Property="Width" Value="20" />
                <Setter Property="Height" Value="20" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Grid>
                                <Rectangle Name="img" Fill="{StaticResource DefaultButtonGradient}">
                                    <Rectangle.OpacityMask>
                                        <ImageBrush ImageSource="Icons/appbar.sound.mute.png"/>
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Effect" TargetName="img" Value="{StaticResource HoverShadowEffect}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>


            <Style x:Key="ActionsStyle" TargetType="ToggleButton">
                <Setter Property="Width" Value="16" />
                <Setter Property="Height" Value="16" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Grid >
                                <Rectangle Name="img" Fill="{StaticResource DefaultButtonGradient}">
                                    <Rectangle.OpacityMask>
                                        <ImageBrush ImageSource="Icons/appbar.list.png"/>
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="ToggleButton.IsChecked" Value="True">
                                    <Setter TargetName="img" Property="Fill" Value="{StaticResource ActivatedButtonGradient}" />
                                </Trigger>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Effect" TargetName="img" Value="{StaticResource HoverShadowEffect}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>     
            <Style x:Key="NotificationsStyle" TargetType="ToggleButton">
                <Setter Property="Width" Value="16" />
                <Setter Property="Height" Value="16" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Grid >
                                <Rectangle Name="img" Fill="{StaticResource DefaultButtonGradient}">
                                    <Rectangle.OpacityMask>
                                        <ImageBrush ImageSource="Icons/appbar.flag.wavy.png"/>
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="ToggleButton.IsChecked" Value="True">
                                    <Setter TargetName="img" Property="Fill" Value="{StaticResource ActivatedButtonGradient}" />   
                                </Trigger>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Effect" TargetName="img" Value="{StaticResource HoverShadowEffect}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <Style x:Key="PlayPauseStyle" TargetType="ToggleButton">
                <Setter Property="Width" Value="16" />
                <Setter Property="Height" Value="16" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Grid>
                                <Rectangle Name="img" Fill="{StaticResource DefaultButtonGradient}">
                                    <Rectangle.OpacityMask>
                                        <ImageBrush ImageSource="Icons/appbar.control.play.png"/>
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="ToggleButton.IsChecked" Value="True">
                                    <Setter TargetName="img" Property="OpacityMask" >
                                        <Setter.Value>
                                            <ImageBrush ImageSource="Icons/appbar.control.pause.png"/>
                                        </Setter.Value>
                                    </Setter>
                                </Trigger>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Effect" TargetName="img" Value="{StaticResource HoverShadowEffect}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <Style x:Key="ResetStyle" TargetType="Button">
                <Setter Property="Width" Value="16" />
                <Setter Property="Height" Value="16" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Grid>
                                <Rectangle Name="img" Fill="{StaticResource DefaultButtonGradient}">
                                    <Rectangle.OpacityMask>
                                        <ImageBrush ImageSource="Icons/appbar.control.rewind.png"/>
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Effect" TargetName="img" Value="{StaticResource HoverShadowEffect}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <Style x:Key="EditStyle" TargetType="Button">
                <Setter Property="Width" Value="16" />
                <Setter Property="Height" Value="16" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Grid>
                                <Rectangle Name="img" Fill="{StaticResource DefaultButtonGradient}">
                                    <Rectangle.OpacityMask>
                                        <ImageBrush ImageSource="Icons/appbar.edit.png"/>
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Effect" TargetName="img" Value="{StaticResource HoverShadowEffect}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <Style x:Key="DeleteStyle" TargetType="Button">
                <Setter Property="Width" Value="16" />
                <Setter Property="Height" Value="16" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Grid>
                                <Rectangle Name="img" Fill="{StaticResource RedButtonGradient}">
                                    <Rectangle.OpacityMask>
                                        <ImageBrush ImageSource="Icons/appbar.delete.png"/>
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Effect" TargetName="img" Value="{StaticResource HoverShadowEffect}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid Grid.Row="0" Visibility="{Binding ShowHeaderMenu, Converter={StaticResource pb2v}, ConverterParameter=true}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <StackPanel Grid.Column="0" Orientation="Horizontal">
                <Image Source="logo.png" Width="24" />
            </StackPanel>
            <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
                <Button Margin="2" Content="Mute" ToolTip="{x:Static p:Resources.MuteAll}" ToolTipService.VerticalOffset="-62"  Command="{Binding StopAllSoundsCommand}" Style="{StaticResource MuteStyle}"></Button>
                <ToggleButton Margin="2" Content="Lock" ToolTip="{x:Static p:Resources.Lock}"  ToolTipService.VerticalOffset="-62" IsChecked="{Binding Locked}" Style="{StaticResource LockStyle}" />
                <ToggleButton Visibility="Collapsed" Margin="2" Content="Show" ToolTipService.VerticalOffset="-62" ToolTip="{x:Static p:Resources.ShowHideCountdowns}" IsChecked="{Binding ShowInactive, Mode=TwoWay, NotifyOnTargetUpdated=True, NotifyOnSourceUpdated=True}" Style="{StaticResource InactiveStyle}"></ToggleButton>
                <Button Margin="2" Content="Neu" ToolTipService.VerticalOffset="-62" ToolTip="{x:Static p:Resources.AddCountdown}" Command="{Binding NewCountdownCommand}" Style="{StaticResource NewStyle}"></Button>
            </StackPanel>
        </Grid>
        <ListView Name="lv" MinHeight="1" ItemsSource="{Binding Countdowns}" Grid.Row="1" Background="Transparent" BorderThickness="0"  ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled">
            <ListView.ItemContainerStyle>
                <Style TargetType="{x:Type ListViewItem}">
                    <Setter Property="Background" Value="Transparent" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ListViewItem}">
                                <ContentPresenter />
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>                   
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.ItemTemplate>
                <DataTemplate DataType="ListViewItem">
                    <Grid Background="Transparent" MouseEnter="Grid_MouseEnter_1" MouseLeave="Grid_MouseLeave_1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid Grid.Column="0" Margin="0,0,20,0">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <TextBlock HorizontalAlignment="Left" Foreground="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}, AncestorLevel=1}, Path=DataContext.Config.TextColor, Converter={StaticResource c2b}}" Grid.Row="0" Text="{Binding Settings.Name}" FontSize="18" VerticalAlignment="Top">
                                <TextBlock.Effect>
                                    <DropShadowEffect BlurRadius="5" ShadowDepth="0"  Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}, AncestorLevel=1}, Path=DataContext.Config.TextBorderColor, Converter={StaticResource c2b}}" />
                                </TextBlock.Effect>
                            </TextBlock>
                            <StackPanel  Grid.Row="1"  Orientation="Horizontal" Visibility="{Binding IsMouseOver,Converter={StaticResource pb2v}, ConverterParameter=true}">
                                <ToggleButton Content="Start/Stop" ToolTip="{x:Static p:Resources.StartStopCountdown}" IsChecked="{Binding StartStop, Mode=TwoWay, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True}" Style="{StaticResource PlayPauseStyle}" Visibility="{Binding Settings.UseDuration, Converter={StaticResource b2v}}" Margin="0,0,15,0" />
                                <Button Content="Edit" ToolTip="{x:Static p:Resources.EditCountdown}"  Style="{StaticResource EditStyle}" Command="{Binding EditCommand}" />
                                <Button Content="Reset" ToolTip="{x:Static p:Resources.ResetCountdown}" Visibility="{Binding Settings.UseDuration, Mode=TwoWay, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, Converter={StaticResource b2v}}" Style="{StaticResource ResetStyle}" Command="{Binding ResetCommand}" Margin="0,0,15,0" />
                                <ToggleButton Visibility="{Binding Path=Settings.HasNotifications, Converter={StaticResource b2v}}" Content="Notify" ToolTip="{x:Static p:Resources.EnableNotify}" IsChecked="{Binding EnableNotifications, Mode=TwoWay, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True}" Style="{StaticResource NotificationsStyle}" />
                                <ToggleButton Visibility="{Binding Path=Settings.HasActions, Converter={StaticResource b2v}}" Content="Actions" ToolTip="{x:Static p:Resources.EnableExec}" IsChecked="{Binding EnableActions, Mode=TwoWay, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True}" Style="{StaticResource ActionsStyle}" />
                                <Button Margin="15,0,0,0" ToolTip="{x:Static p:Resources.DeleteCountdown}" Content="Delete" Style="{StaticResource DeleteStyle}" Command="{Binding RelativeSource={RelativeSource FindAncestor, 
AncestorType={x:Type ListView}}, Path=DataContext.DeleteCommand}" CommandParameter="{Binding .}" />
                            </StackPanel>
                        </Grid>
                        <StackPanel Grid.Column="1">
                            <TextBlock Foreground="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}, AncestorLevel=1}, Path=DataContext.Config.TextColor, Converter={StaticResource c2b}}" Text="{Binding Left, Converter={StaticResource tsts}}" MouseDown="TextBlock_MouseDown"  HorizontalAlignment="Right" FontSize="28">
                                <TextBlock.Effect>
                                    <DropShadowEffect BlurRadius="5" ShadowDepth="0"  Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}, AncestorLevel=1}, Path=DataContext.Config.TextBorderColor, Converter={StaticResource c2b}}" />
                                </TextBlock.Effect>
                            </TextBlock>

                            <TextBlock  Foreground="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}, AncestorLevel=1}, Path=DataContext.Config.TextColor, Converter={StaticResource c2b}}" Text="{Binding CurrentEndDate}" HorizontalAlignment="Right">
                                <TextBlock.Effect>
                                    <DropShadowEffect BlurRadius="5" ShadowDepth="0"  Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}, AncestorLevel=1}, Path=DataContext.Config.TextBorderColor, Converter={StaticResource c2b}}" />
                                </TextBlock.Effect>
                            </TextBlock>

                        </StackPanel>

                    </Grid>

                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</UserControl>
